using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;

namespace DocLibApp
{
    partial class FormAbout : FormBase
    {
        public FormAbout()
        {
            InitializeComponent();

            GetApplicationInformation();
            GetStatInfo();
        }

        private void GetApplicationInformation()
        {
            labelProductName.Text = GetAppCode("APP_TITLE");
            labelVersion.Text = GetAppCode("APP_VERSION");
            labelCopyright.Text = GetAppCode("APP_COPYRIGHT");
            labelCompanyName.Text = GetAppCode("APP_COMPANY");
            textBoxDescription.Text = GetAppCode("APP_DESCRIPTION");

            //Load Registration information
            //checking user license info by loading license file and parsing it
            string RegInfo = "(This program is not yet registered.)";

            if (System.IO.File.Exists(def.FileName_DefaultLicense))
            {
                List<string> info = doc_system.GetLicenseInfo(def.FileName_DefaultLicense);
                if (info.Count > 0)
                {
                    string lic_user = info[0];
                    string lic_company = info[1];
                    string lic_num = info[2];
                    string lic_key = info[3];

                    try
                    {
                        if (util.IfKeyIsValid(lic_user, lic_company, lic_num, lic_key))
                        {
                            RegInfo = " (Registered to: " + lic_user + " of " + lic_company + ")";
                        }
                    }
                    catch (System.Exception)
                    {
                        ShowMessage("Invalid registration information.");
                    }
                }

                this.Text = "About " + RegInfo;
            }
            else
            {
                this.Text = "About " + RegInfo;
            }
        }

        private void GetStatInfo()
        {
            string sTotalDocCount = doc_info.GetTotalDocumentCount();
            textBoxDescription.Text += System.Environment.NewLine + System.Environment.NewLine + sTotalDocCount + " documents.";
        }

        private void logoPictureBox_Click(object sender, EventArgs e)
        {
            string url = GetAppCode("APP_URL");
            util.RunFile(url);
        }
    }
}
